<?php
/**
 * Hesperos library for Zend Framework
 *
 * This script is protected by copyright. It's use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    Hesperos
 * @package     Log
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id: Manager.php 4 2011-05-09 14:57:19Z krzysztof.kardasz $
 * @link        http://code.google.com/p/hesperos/
 */

/**
 * Menadżer dziennika zdarzeń
 *
 * @category    Hesperos
 * @package     Log
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @version     1.0 $Id: Manager.php 4 2011-05-09 14:57:19Z krzysztof.kardasz $
 */
class Hesperos_Log_Manager
{
    /**
     * Mapowanie kolumn tabeli
     *
     * @var array
     */
    private static $_dbColumnMapping = array(
    	Application_Model_Table_Log::FIELD_PRIORITY => 'priority',
    	Application_Model_Table_Log::FIELD_MESSAGE  => 'message'
    );

    /**
     * Nazwa tabeli
     *
     * @var string
     */
    private static $_dbTableName = 'tbl_log';

    /**
     * Obiekt klasy Zend_Log
     *
     * @var null|Zend_Log
     */
    private static $_db = null;

    /**
     * Obiekt klasy Zend_Log
     *
     * @var null|Zend_Log
     */
    private static $_log = null;

    /**
     * Zwraca obiekt klasy Zend_Log
     *
     * @return Zend_Log
     */
    public static function getLog ()
    {
        if(null === self::$_default) {
            self::$_log = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('log');
        }
        return self::$_log;
    }

    /**
     * Zwraca obiekt klasy Zend_Log (skonfigurowany z bazą danych)
     *
     * @return Zend_Log
     */
    public static function getDb ()
    {
        if(null === self::$_log) {
            $writer = new Zend_Log_Writer_Db(
                Zend_Db_Table::getDefaultAdapter(),
                self::$_dbTableName,
                self::$_dbColumnMapping
            );
            self::$_db = new Zend_Log($writer);
        }
        return self::$_db;
    }
}